﻿// Accord Math Library
// Accord.NET framework
// http://www.crsouza.com
//
// Copyright © César Souza, 2009-2010
// cesarsouza at gmail.com
//

namespace Accord.Math
{
    using System;

    /// <summary>
    ///   Set of mathematical tools.
    /// </summary>
    public static class Tools
    {

        #region Framework-wide random number generator
        private static Random random = new Random();

        /// <summary>
        ///   Gets a reference to the random number generator used
        ///   internally by the Accord.NET classes and methods.
        /// </summary>
        public static Random Random { get { return random; } }

        /// <summary>
        ///   Sets a random seed for the internal number generator.
        /// </summary>
        /// <remarks>
        ///   This method is only available in the debug version
        ///   of the framework.
        /// </remarks>
        [System.Diagnostics.Conditional("DEBUG")]
        public static void SetRandomSeed(int seed)
        {
#if DEBUG
            random = new Random(seed);
#endif
        }
        #endregion



        /// <summary>
        ///   Converts the value x (which is measured in the scale
        ///   'from') to another value measured in the scale 'to'.
        /// </summary>
        public static double Scale(double fromMin, double fromMax, double toMin, double toMax, double x)
        {
            if (fromMax - fromMin == 0) return 0;
            return (toMax - toMin) * (x - fromMin) / (fromMax - fromMin) + toMin;
        }

    }

}